<include file="../Public/_header" />
<div class="so_main">
  <div class="page_tit">组件管理</div>
  
  <div class="Toolbar_inbox">
  	<div class="page right">{$html}</div>
	<a href="{:U('admin/Widget/addWidget')}" class="btn_a"><span>添加组件</span></a>
	<a href="javascript:void(0);" class="btn_a" onclick="deleteWidget();"><span>删除组件</span></a>
  </div>
  <div class="list">
  <table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <th style="width:30px;">
		<input type="checkbox" id="checkbox_handle" onclick="checkAll(this)" value="0">
    	<label for="checkbox"></label>
	</th>
    <th class="line_l">ID</th>
    <th class="line_l">组件名称</th>
    <th class="line_l">组件别名</th>
     <th class="line_l">组件类型</th>
    <th class="line_l">组件简介</th>
    <th class="line_l">状态</th>
    <th class="line_l">操作</th>
  </tr>
  <volist id="vo" name="data">
	  <tr overstyle='on' id="widget_{$vo['id']}">
	    <td><input type="checkbox" name="checkbox" id="checkbox2" onclick="checkon(this)" value="{$vo.id}"></td>
	    <td>{$vo.id}</td>
	    <td>{$vo.widget_name}</td>
		<td>{$vo.widget_alias}</td>
		<td>{$widget_types[$vo[widget_type]]}</td>
	    <td>{$vo.description}</td>
	    <td><eq name="vo['status']" value="0">未启用<else/>启用</else></eq></td>
	    <td>
			<a href="{:U('admin/Widget/editWidget', array('id'=>$vo['id']))}">编辑</a>
	    	<a href="javascript:void(0);" onclick="deleteWidget({$vo['id']});">删除</a>
		</td>
	  </tr>
  </volist>
  </table>
  </div>

  <div class="Toolbar_inbox">
	<div class="page right">{$html}</div>
	<a href="{:U('admin/Widget/addWidget')}" class="btn_a"><span>添加组件</span></a>
	<a href="javascript:void(0);" class="btn_a" onclick="deleteWidget();"><span>删除组件</span></a>
  </div>
</div>

<script>
	//鼠标移动表格效果
	$(document).ready(function(){
		$("tr[overstyle='on']").hover(
		  function () {
		    $(this).addClass("bg_hover");
		  },
		  function () {
		    $(this).removeClass("bg_hover");
		  }
		);
	});
	
	function checkon(o){
		if( o.checked == true ){
			$(o).parents('tr').addClass('bg_on') ;
		}else{
			$(o).parents('tr').removeClass('bg_on') ;
		}
	}
	
	function checkAll(o){
		if( o.checked == true ){
			$('input[name="checkbox"]').attr('checked','true');
			$('tr[overstyle="on"]').addClass("bg_on");
		}else{
			$('input[name="checkbox"]').removeAttr('checked');
			$('tr[overstyle="on"]').removeClass("bg_on");
		}
	}

	//获取已选择组件的ID数组
	function getChecked() {
		var ids = new Array();
		$.each($('table input:checked'), function(i, n){
			ids.push( $(n).val() );
		});
		return ids;
	}
 
	
	//删除组件
	function deleteWidget(id) {
		id = id ? id : getChecked();
		id = id.toString();
		if(id == '' || !confirm('删除成功后将无法恢复，确认继续？')) return false;
		
		$.post("{:U('admin/Widget/doDeleteWidget')}", {id:id}, function(res){
			if(res == '1') {
				id = id.split(',');
				for(i = 0; i < id.length; i++) {
					$('#widget_'+id[i]).remove();
				}
				ui.success('操作成功');
			}else {
				ui.error('操作失败');
			}
		});
	}
</script>

<include file="../Public/_footer" />